using System;
using System.Collections.Generic;
using System.Text;
using DataTools;
using DataTools.PagingUtils;
using ObjectLayer;

namespace CommonAccessLayer
{
	public class department_permissionDAO
{
		public static List<department_permissionBO> GetAll()
		{
			return CBO.FillCollection<department_permissionBO>(DataProvider.getInstance().getAll(TableName.department_permission, PagingHelper.CreateOrder(new OrderObject(department_permissionTable.department_id, SortOrder.Desc))));
		}
		static object _Clock = new object();
		public static List<department_permissionBO> GetAllC()
		{
			List<department_permissionBO> list = new List<department_permissionBO>();
			if(DataCache.GetCache(CacheName.department_permission) == null)
			{
				lock (_Clock)
				{
					if (DataCache.GetCache(CacheName.department_permission) != null)
					{
						list = (List<department_permissionBO>)DataCache.GetCache(CacheName.department_permission);
					}
					else
					{
			list = CBO.FillCollection<department_permissionBO>(DataProvider.getInstance().getAll(TableName.department_permission, PagingHelper.CreateOrder(new OrderObject(department_permissionTable.department_id, SortOrder.Desc))));
						DataCache.SetCache(CacheName.department_permission, list);
					}
				}
			}
			else
			{
					list = (List<department_permissionBO>)DataCache.GetCache(CacheName.department_permission);
			}
		return list;
		}
		public static int InsertUpdateDelete(department_permissionBO department_permission, ProviderAction action)
		{
			int rs = DataProvider.getInstance().InsertUpdateDelete(action, StoreProcedureName.InsertUpdateDelete_department_permission, "@" + department_permissionTable.department_id, department_permission.department_id,department_permission.screen_id,department_permission.permission, DataTools.ConvertType.ToInt(action));
			if (rs != -1)
			{
				DataCache.RemoveCache(CacheName.department_permission);
			}
			return rs;
		}
		public static int Insert(department_permissionBO department_permission)
		{
			 return InsertUpdateDelete(department_permission, ProviderAction.Insert);
		}
		public static int Update(department_permissionBO department_permission)
		{
			 return InsertUpdateDelete(department_permission, ProviderAction.Update);
		}
		public static int Delete(department_permissionBO department_permission)
		{
			 return InsertUpdateDelete(department_permission, ProviderAction.Delete);
		}
		public static int Delete(int department_id)
		{
			department_permissionBO department_permission = new department_permissionBO(department_id);
			return Delete(department_permission);
		}
	}
}